using System;
using System.Web.UI.WebControls;
using Sedna.Core.Common.Objects.Navigation;

namespace Sedna.Core.Controller.Configurations
{
	public class DefaultIdGenerator: IDataGridInnerControlIdGenerator
	{
		private string rowIdPath="Id";
//		private IList compoundRowIdPath;
		private string template="__control__{0}__{1}";
        private IScopePathParser scopePathParser;


	    public IScopePathParser ScopePathParser
	    {
	        set { scopePathParser = value; }
	    }

	    public string RowIdPath
		{
			set { rowIdPath = value; }
		}

//		public IList CompoundRowIdPath
//		{
//			set { compoundRowIdPath = value; }
//		}

		public string Template
		{
			set { template = value; }
		}

		public string Generate(IDataGridColumnConfiguration columnConfiguration, int columnIndex,  DataGridItem dataGridItem, IExecutionContext executionContext)
		{
			return String.Format(template, scopePathParser.Parse(dataGridItem.DataItem, rowIdPath).Value, columnConfiguration.DataField);
		}

//		private string PrepareIdPart(string str)
//		{
//			return Regex.Replace(str, "[^a-zA-Z0-9_]", "_");
//		}

//		private string GetRowIdPart(object dataItem)
//		{
////			if (compoundRowIdPath!=null)
////			{
////				//TODO
////			}
//
//			
//		}
	}
}
